/* 
  1.该文件是用于创建一个为Count组件服务的reducer，reducer的本质就是一个函数
  2.reducer函数会接到两个参数，分别为：之前的状态(preState)，动作对象(action)
*/
export default function allnumReducer(preState, action) {
  console.log(preState);
  if (!preState || JSON.stringify(preState) === '{}') {
    if(localStorage.getItem('persist:root')){
      const NewObj1 = { 'preState': Number(JSON.parse(localStorage.getItem('persist:root'))['preState']) }
      return NewObj1
    }else {
      const NewObj2 = { 'preState': '' }
      return NewObj2
    }
  }else {
    console.log(preState);
    //从action对象中获取：type、data
    const { type, data } = action
    //根据type决定如何加工数据
    console.log(type, data);
    if (type === 'allnumber') {
      preState = data
      console.log(preState);
      const NewObj = { 'preState': preState }
      return NewObj
    }
  }
}